package com.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类：配置默认打开自定义的浏览器
 * 启动服务打开浏览器
 */
@Configuration
public class MyRunner implements CommandLineRunner {
    @Value("${url}")
    private String url;
    @Value("${googleexcute}")
    private String googleExcutePath;
    @Value("${openurl}")
    private boolean isOpen;
    @Value("${server.port}")
    private String port;
    @Override
    public void run(String... args) throws Exception {
        if(isOpen){
            //在这里可以加项目的路径，在没有加的时候，默认访问的是8080端口
            //String cmd = googleExcutePath +" http://"+ url+":"+port+"所要访问的路径";
            String cmd = googleExcutePath +" http://"+ url+":"+port;
            Runtime run = Runtime.getRuntime();
            try{
                run.exec(cmd);
                System.out.println("启动浏览器程序成功");
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
